---
title: "Kastrax Core"
description: Documentation for the Kastrax Class, the core entry point for managing agents, workflows, and server endpoints.
---

# The Kastrax Class ✅

The Kastrax class is the core entry point for your application. It manages agents, workflows, and server endpoints.

## Constructor Options ✅

<PropertiesTable
  content={[
    {
      name: "agents",
      type: "Agent[]",
      description: "Array of Agent instances to register",
      isOptional: true,
      defaultValue: "[]",
    },
    {
      name: "tools",
      type: "Record<string, ToolApi>",
      description:
        "Custom tools to register. Structured as a key-value pair, with keys being the tool name and values being the tool function.",
      isOptional: true,
      defaultValue: "{}",
    },
    {
      name: "storage",
      type: "KastraxStorage",
      description: "Storage engine instance for persisting data",
      isOptional: true,
    },
    {
      name: "vectors",
      type: "Record<string, KastraxVector>",
      description:
        "Vector store instance, used for semantic search and vector-based tools (eg Pinecone, PgVector or Qdrant)",
      isOptional: true,
    },
    {
      name: "logger",
      type: "Logger",
      description: "Logger instance created with createLogger()",
      isOptional: true,
      defaultValue: "Console logger with INFO level",
    },
    {
      name: "workflows",
      type: "Record<string, Workflow>",
      description: "Workflows to register. Structured as a key-value pair, with keys being the workflow name and values being the workflow instance.",
      isOptional: true,
      defaultValue: "{}",
    },
    {
      name: "server",
      type: "ServerConfig",
      description: "Server configuration including port, host, timeout, API routes, middleware, CORS settings, and build options for Swagger UI, API request logging, and OpenAPI docs.",
      isOptional: true,
      defaultValue: "{ port: 4111, host: localhost,  cors: { origin: '*', allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowHeaders: ['Content-Type', 'Authorization', 'x-kastrax-client-type'], exposeHeaders: ['Content-Length', 'X-Requested-With'], credentials: false } }",
    },
  ]}
/>

## Initialization ✅

The Kastrax class is typically initialized in your `src/kastrax/index.ts` file:

```typescript copy filename=src/kastrax/index.ts
import { Kastrax } from "@kastrax/core";
import { createLogger } from "@kastrax/core/logger";

// Basic initialization
export const kastrax = new Kastrax({});

// Full initialization with all options
export const kastrax = new Kastrax({
  agents: {},
  workflows: [],
  integrations: [],
  logger: createLogger({
    name: "My Project",
    level: "info",
  }),
  storage: {},
  tools: {},
  vectors: {},
});
```

You can think of the `Kastrax` class as a top-level registry. When you register tools with Kastrax, your registered agents and workflows can use them. When you register integrations with Kastrax, agents, workflows, and tools can use them.

## Methods ✅

<PropertiesTable
  content={[
    {
      name: "getAgent(name)",
      type: "Agent",
      description:
        "Returns an agent instance by id. Throws if agent not found.",
      example: 'const agent = kastrax.getAgent("agentOne");',
    },
    {
      name: "getAgents()",
      type: "Record<string, Agent>",
      description:
        "Returns all registered agents as a key-value object.",
      example: 'const agents = kastrax.getAgents();',
    },
    {
      name: "getWorkflow(id, { serialized })",
      type: "Workflow",
      description:
        "Returns a workflow instance by id. The serialized option (default: false) returns a simplified representation with just the name.",
      example: 'const workflow = kastrax.getWorkflow("myWorkflow");',
    },
    {
      name: "getWorkflows({ serialized })",
      type: "Record<string, Workflow>",
      description:
        "Returns all registered workflows. The serialized option (default: false) returns simplified representations.",
      example: 'const workflows = kastrax.getWorkflows();',
    },
    {
      name: "getVector(name)",
      type: "KastraxVector",
      description:
        "Returns a vector store instance by name. Throws if not found.",
      example: 'const vectorStore = kastrax.getVector("myVectorStore");',
    },
    {
      name: "getVectors()",
      type: "Record<string, KastraxVector>",
      description:
        "Returns all registered vector stores as a key-value object.",
      example: 'const vectorStores = kastrax.getVectors();',
    },
    {
      name: "getDeployer()",
      type: "KastraxDeployer | undefined",
      description:
        "Returns the configured deployer instance, if any.",
      example: 'const deployer = kastrax.getDeployer();',
    },
    {
      name: "getStorage()",
      type: "KastraxStorage | undefined",
      description:
        "Returns the configured storage instance.",
      example: 'const storage = kastrax.getStorage();',
    },
    {
      name: "getMemory()",
      type: "KastraxMemory | undefined",
      description:
        "Returns the configured memory instance. Note: This is deprecated, memory should be added to agents directly.",
      example: 'const memory = kastrax.getMemory();',
    },
    {
      name: "getServer()",
      type: "ServerConfig | undefined",
      description:
        "Returns the server configuration including port, timeout, API routes, middleware, CORS settings, and build options.",
      example: 'const serverConfig = kastrax.getServer();',
    },
    {
      name: "setStorage(storage)",
      type: "void",
      description:
        "Sets the storage instance for the Kastrax instance.",
      example: 'kastrax.setStorage(new DefaultStorage());',
    },
    {
      name: "setLogger({ logger })",
      type: "void",
      description:
        "Sets the logger for all components (agents, workflows, etc.).",
      example: 'kastrax.setLogger({ logger: createLogger({ name: "MyLogger" }) });',
    },
    {
      name: "setTelemetry(telemetry)",
      type: "void",
      description:
        "Sets the telemetry configuration for all components.",
      example: 'kastrax.setTelemetry({ export: { type: "console" } });',
    },
    {
      name: "getLogger()",
      type: "Logger",
      description:
        "Gets the configured logger instance.",
      example: 'const logger = kastrax.getLogger();',
    },
    {
      name: "getTelemetry()",
      type: "Telemetry | undefined",
      description:
        "Gets the configured telemetry instance.",
      example: 'const telemetry = kastrax.getTelemetry();',
    },
    {
      name: "getLogsByRunId({ runId, transportId })",
      type: "Promise<any>",
      description:
        "Retrieves logs for a specific run ID and transport ID.",
      example: 'const logs = await kastrax.getLogsByRunId({ runId: "123", transportId: "456" });',
    },
    {
      name: "getLogs(transportId)",
      type: "Promise<any>",
      description:
        "Retrieves all logs for a specific transport ID.",
      example: 'const logs = await kastrax.getLogs("transportId");',
    },
  ]}
/>

## Error Handling ✅

The Kastrax class methods throw typed errors that can be caught:

```typescript copy
try {
  const tool = kastrax.getTool("nonexistentTool");
} catch (error) {
  if (error instanceof Error) {
    console.log(error.message); // "Tool with name nonexistentTool not found"
  }
}
```
